<template>
  <el-dialog
    :title="title"
    :visible.sync="openDlg"
    v-if="openDlg"
    width="30%"
    append-to-body
    destroy-on-close
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="批次名称" prop="batchId">
            <el-select
              v-model="form.batchId"
              placeholder="请选择"
              clearable
              class="elSelect"
              style="width: 100%;"
            >
              <el-option
                v-for="dict in list"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="辅导员姓名" prop="selectedObject">
            <el-select
              v-model="form.selectedObject"
              filterable
              placeholder="请选择"
              clearable
              @change="optionsArray"
              style="width: 100%;"
            >
              <el-option
                v-for="item in counselorList"
                :key="item.value"
                :label="item.label"
                :value="item"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="所在部门">
            <el-input v-model="form.collegeName" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" >
          <el-form-item label="考核等级" prop="checkLevel">
            <el-select
              v-model="form.checkLevel"
              placeholder="请选择"
              clearable
              class="elSelect"
              style="width: 100%;"
            >
              <el-option
                v-for="dict in dict.type.clr_sum_rank"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="分数" prop="score">
            <el-input v-model.trim="form.score" placeholder="请输入分数" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="openDlg = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
    
    <script>

import { counsellorList } from "@/api/counselor/index.js";
import { addCheckrecord,updateCheckrecord } from "@/api/clr/statistics";

export default {
  name: "batchAdd",
  dicts: ["clr_sum_rank"],
  props: {
    list: {
      type: Array,
      default: "",
    },
  },
  data() {
    return {
      title: "",
      openDlg: false,
      // 表单参数
      form: {
        batchId: "",
        checkLevel: "",
        score: "",
      },
      // 表单校验
      rules: {
        batchId: [{ required: true, message: "请选择批次名称", trigger: "change" }],
        checkLevel: [{ required: true, message: "请选择考核等级", trigger: "change" }],
        selectedObject: [{ required: true, message: "请选择辅导员", trigger: "change" }],
        score: [
          { required: true, message: "请输入分数", trigger: "blur" },
        ],
      },
      queryParams: {
        pageNum: 1,
        pageSize: 200,
        deptId: "",
        selectedObject: null,
      },
      userNum: 0,
      moneyNum: 0,
     
      yearStr: "",
    
      hasTypes: [],
      dlgType: "add",
      counselorList: [],
    };
  },
  watch: {
   
  },
  methods: {
   
 
    open(type, rowdata) {
      
      this.selectClr();
      this.dlgType = type;
      if (type == "add") {
        this.title = "新增";
        this.form = {}
      } else {
        this.title = "编辑";
      
      this.form = rowdata
      this.form.selectedObject = rowdata.clrName
      console.log(this.form,'传递的参数')
      }
      this.openDlg = true;
    },
    // 查询辅导员信息
    async selectClr() {
      const data = await counsellorList(this.queryParams);
      this.counselorList = data.rows.map((item) => {
        return {
          value: item.cId,
          label: item.teacher.name,
          dept: item.teacher.deptNames,
          tId: item.tId,
        };
      });
      console.log(this.counselorList, "辅导员信息");
    },
    optionsArray() {
      console.log(this.selectedObject, "选中");
      this.form.tId = this.form.selectedObject.tId;
      this.form.cId = this.form.selectedObject.value;
      this.form.clrName = this.form.selectedObject.label;
      this.form.collegeName = this.form.selectedObject.dept;
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cesrId != null) {
           
            updateCheckrecord(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.openDlg = false;
              this.$emit("onSearch");
            });
          } else {
            addCheckrecord(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.openDlg = false;
              this.$emit("onSearch");
            });
          }
        }
      });
    },
  },
};
</script>
    
    <style lang="scss" scoped>
.planTotal {
  display: flex;
  font-size: 13px;
  color: #606266;
  &-left {
    margin-left: 30px;
  }
  &-right {
    margin-left: 20px;
  }
}
</style>